# -*- coding: utf-8 -*-
"""
Module Description:
Date: 2018/04/18
Author:Sky
"""
from pyshare.utils.time_utils import getCT, has_pass_time, get_another_time
from pyshare.dal.gameconfig.game_env import get_config_env_set
from pyshare.const.enums.activity import GrowthPlanStatus


class GrowthPlanMixin(object):
    __slots__ = ()
    start_time = NotImplemented
    end_time = NotImplemented
    activity_status = NotImplemented

    @property
    def is_time_open(self):
        # 活动时间是否有效
        return self.start_time <= getCT() < self.end_time

    @property
    def is_time_not_start(self):
        # 活动时间是否未开始
        return getCT() < self.start_time

    @property
    def is_expire(self):
        # 活动是否过期
        return self.end_time <= getCT()

    @property
    def is_expire_clear(self):
        # 是否到了活动记录删除状态
        return has_pass_time(self.end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.activity_status == GrowthPlanStatus.Opening


class RoleGrowthPlanMixin(object):
    __slots__ = ()
    create_time = NotImplemented
    end_time = NotImplemented

    @property
    def days(self):
        # 当前为购买后的第几天
        return (getCT().replace(hour=0, minute=0, second=0) - self.create_time.replace(
            hour=0, minute=0, second=0, microsecond=0)).days

    @property
    def is_time_open(self):
        # 活动时间是否有效
        return self.create_time <= getCT() < self.end_time

    @property
    def is_time_not_start(self):
        # 活动时间是否未开始
        return getCT() < self.create_time

    @property
    def is_expire(self):
        # 活动是否过期
        return self.end_time <= getCT()

    @property
    def is_expire_clear(self):
        # 是否到了活动记录删除状态
        return has_pass_time(self.end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.end_time, seconds=30)
